package com.spring;

import com.spring.beans.PropertyValues;

import java.util.Objects;

/**
 * @Author: Asuka
 * @Description:
 * @create: 2025-04-05 19:15
 */


public class BeanDefinition {

    //单例
    public static String SCOPE_SINGLETON = "singleton";
    private boolean singleton = true;

    //非单例
    public static String SCOPE_PROTOTYPE = "prototype";
    private boolean prototype = false;

    private String scope = SCOPE_SINGLETON;




    private Class beanClass;

    //懒加载
    private boolean lazyInit=false;



    //class属性值
    private PropertyValues propertyValues;

    //通过反射 初始化方法名称
    private String initMethodName;

    //销毁方法名称
    private String destroyMethodName;


    public void toSingleton(){
        this.singleton = true;
        this.prototype = false;
        this.scope = SCOPE_SINGLETON;
    }

    public void toPrototype(){
        this.singleton = false;
        this.prototype = true;
        this.scope = SCOPE_PROTOTYPE;
    }


    public BeanDefinition(Class beanClass) {
        this(beanClass, null);
    }

    public BeanDefinition(Class beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = propertyValues != null ? propertyValues : new PropertyValues();
    }


    public void setBeanClass(Class beanClass) {
        this.beanClass = beanClass;
    }

    public Class getBeanClass() {
        return beanClass;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public boolean isSingleton() {
        return this.singleton;
    }

    public boolean isPrototype() {
        return this.prototype;
    }


    public PropertyValues getPropertyValues() {
        return propertyValues;
    }

    public void setPropertyValues(PropertyValues propertyValues) {
        this.propertyValues = propertyValues;
    }

    public String getInitMethodName() {
        return initMethodName;
    }

    public void setInitMethodName(String initMethodName) {
        this.initMethodName = initMethodName;
    }

    public String getDestroyMethodName() {
        return destroyMethodName;
    }

    public void setDestroyMethodName(String destroyMethodName) {
        this.destroyMethodName = destroyMethodName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        BeanDefinition that = (BeanDefinition) o;
        return beanClass.equals(that.beanClass);
    }

    @Override
    public int hashCode() {
        return Objects.hash(beanClass);
    }

    public void setLazyInit(boolean b){
        lazyInit=b;
    }

    public boolean isLazyInit(){
        return lazyInit;
    }


}
